home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12165 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: news1.intercall.com!usenet
  2. From: engevar@intercall.com (Steven Ovits)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: I need help.
  5. Date: Fri, 29 Mar 1996 17:51:23 GMT
  6. Organization: Intercall Inc.
  7. Message-ID: <4jguak$n6e@news1.intercall.com>
  8. References: <4j9hr7$skj@cronkite.seas.gwu.edu> <26MAR199615081545@erich.triumf.ca> <danpop.828046690@rscernix>
  9. NNTP-Posting-Host: ts2-98.intercall.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. danpop@mail.cern.ch (Dan Pop) wrote:
  13.  
  14. >In <26MAR199615081545@erich.triumf.ca> bennett@erich.triumf.ca (P.Bennett) writes:
  15.  
  16. >>In article <4j9hr7$skj@cronkite.seas.gwu.edu>, celtik@gwis2.circ.gwu.edu (Tolga Celtikci) writes...
  17. >>>Can anyone help me with the syntax of EOF. Is it '\o' or something else?
  18.  
  19. >The "syntax" of EOF is EOF.  It works fine after including <stdio.h>.
  20.  
  21. Agreed.
  22.  
  23. >On _some_ platforms it can be even written as a character constant: '\xff'
  24. >or '\377', but:
  25.  
  26. >1. It is a very "efficient" way to obfuscate your code.  Other people
  27. >   will have a very hard time figuring out what you meant.
  28.  
  29. >2. It will work only on platforms which use two's complement integers, 
  30. >   define EOF as -1 and treat char as an 8-bit signed type.  OTOH, EOF
  31. >   works everywhere.
  32.  
  33. >>EOF is _not_ a char in the file.  It is a value returned by getchar(), fgetc()
  34. >>and some other functions to indicate that they have attempted to read past
  35. >>end-of-file.   It is a value that cannot be represented in a char, so getchar()
  36. >                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  37. >Don't be so sure.  Implementations with sizeof(char) == sizeof(int) are
  38. >legal and even exist.  They're a royal pain in the ass when it comes to
  39. >testing for EOF, because EOF is also a valid character value, so after
  40. >reading an EOF you have to call ferror and feof to disambiguate between
  41. >a genuine char value and an end-of-file condition.
  42.  
  43. This is correct, but the following will make it more definitive.
  44. I quote from the standard section of "The Standard C Library"
  45. by P. J. Plauger: 
  46.  
  47. "EOF which expands to an integral constant expression that is
  48. returned by several functions to indicate 'end-of-file,' that is,
  49. no more input from a stream."
  50.  
  51. Notice it says nothing about whether the constant is valid in a file,
  52. so it can be.
  53.  
  54. "The feof function test the 'end-of-file' indicator for the stream
  55. pointed to by stream."
  56.  
  57. Therefore, it is a good idea to always use feof and only feof to
  58. test for the end of input.
  59.  
  60. The only caveat I'm aware of is that a system is free to pad
  61. binary files with an 0 bytes, so the end-of-file may or may not be
  62. reported--I don't know the standard or practice on this.
  63.  
  64. My only question is why would you have to test ferror? Is this
  65. related to the problem some systems have of distinguishing the
  66. end-of-file?
  67.  
  68.  
  69.